<template>
  <el-dialog
    title="关联列表" :visible.sync="choseDoubtful" append-to-body height="450" width="80%" @open="onSearch()" @close="cancelDialog">
    <el-container>
      <el-header style="height: auto">
        <el-form ref="queryForm" :inline="true" :model="query" class="demo-form-inline">
          <el-form-item label="项目名称">
            <el-input v-model="query.projectName" placeholder="请输入项目名称" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSearch()">搜索</el-button>
            <el-button @click="searchReset()">重置</el-button>
          </el-form-item>
        </el-form>
      </el-header>
      <el-main>
        <el-table ref="projectTable" :data="data" border row-key="pointId" height="300" style="width: 100%">
          <el-table-column prop="projectName" label="审计项目名称"></el-table-column>
          <el-table-column prop="pointCode" label="疑点编号"></el-table-column>
          <el-table-column prop="pointDesc" label="疑点描述"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="primary" size="small" @click="relateClick(scope.row)">选择</el-button>
<!--              <el-button type="primary" size="small" @click="addOrUpdateHandle(scope.row, true)">详情</el-button>-->
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          @size-change="sizeChange"
          @current-change="currentChange"
          :current-page="page.current"
          :page-sizes="[10, 20, 30, 40, 50, 100]"
          :page-size="10"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total">
        </el-pagination>
      </el-main>
<!--      <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @cancelDialog="closeDoubtfulDialog"></table-form>-->
    </el-container>
  </el-dialog>
</template>

<script>
import {fetchDoubtfulList} from '@/api/adis/execute/point'
// import TableForm from "@/components/form/projectSummaryForm";

export default {
  components: {
    // TableForm,
  },
  name: 'chose-doubtful',
  props: {
  },
  data() {
    return {
      addOrUpdateVisible: false,
      choseDoubtful: false,
      query: {
        userId: null,
        username: '',
        phone: '',
      },
      page: {
        size: 10,
        current: 1,
        total: 0
      },
      data: [],
      relateData: {},
    }
  },
  methods: {
    initParams(params) {
      this.params = params;
      this.choseDoubtful = true;
      this.page.current = 1;
      this.doubtfulList(this.page);
    },
    // 新增 / 修改
    addOrUpdateHandle (row, type) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(row, type)
      })
    },
    closeDoubtfulDialog() {
      this.selectedRowsId = ''
      this.addOrUpdateVisible = false
      this.doubtfulList(this.page);
    },
    formatProjectDate(row, column) {
      const date = row.projectDate;
      if (date) {
        return date.split('-')[0];
      }
      return '';
    },
    // 确认
    confirmDialog() {
      this.$emit('setValue', this.relateData)
      this.relateData = {}
      this.cancelDialog()
    },
    // 关闭
    cancelDialog() {
      this.choseDoubtful = false;
      this.$refs['queryForm'].resetFields()
    },
    onSearch() {
      this.page.current = 1;
      this.doubtfulList(this.page);
    },
    searchReset() {
      this.query = {};
      this.page.current = 1;
      this.doubtfulList(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.current = 1;
      this.doubtfulList(this.page, params);
      done();
    },
    currentChange(current) {
      this.page.current = current;
      this.doubtfulList(this.page, this.query);
    },
    sizeChange(size) {
      this.page.size = size;
      this.doubtfulList(this.page, this.query);
    },
    doubtfulList(page, params = {}) {
      this.loading = true;
      fetchDoubtfulList(Object.assign(params, this.query, this.params, page)).then(res => {
        this.loading = false;
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
      }, () => {
        this.loading = false;
      });
    },
    relateClick(val) {
      this.relateData = val;
      this.confirmDialog();
    }
  }
}
</script>

<style>
</style>
